<template>
    <div class="timing">
        <el-row style="margin-bottom:10px;">
            <el-col :span="24">
                <el-button type="primary" @click="synchQyronous">部门数据同步</el-button>
            </el-col>
        </el-row>
       <el-table
       class="tableAutoBtn"
        :data="tableUserData"
        v-loading="loading"
        border
        :header-cell-style="getRowClass"
        :row-class-name="tableRowClassName"
        row-key="id"
        :tree-props="{children: 'children', hasChildren: 'hasChildren'}"
        style="width: 100%"
    >
        <el-table-column
            type="index"
            label="序号"
            align="center"
            width="50"
        />
        <el-table-column
            prop="deptName"
            label="部门名称"
            align="center"
        />
        <el-table-column
            prop="leader"
            label="领导"
            align="center"
        />
        <el-table-column
        prop=""
        label="操作"
        width="220"
        align="center"
        >
        <template slot-scope="scope">
            <el-button size="mini" type="text" @click="getDepUser(scope.row.id)">查看部门用户</el-button>
        </template>
        </el-table-column>
    </el-table>
    <el-dialog
        title="查看部门用户"
        :visible.sync="dialogVisible"
        width="50%"
        :before-close="handleClose">
        <el-table
            class="tableAutoBtn"
            :data="tableUserData2"
            border
            :header-cell-style="getRowClass"
            :row-class-name="tableRowClassName"
            row-key="id"
            :tree-props="{children: 'children', hasChildren: 'hasChildren'}"
            style="width: 100%"
            >
                <el-table-column
                    type="index"
                    label="序号"
                    align="center"
                    width="50"
                />
                <el-table-column
                    prop="userRealName"
                    label="姓名"
                    align="center"
                />
                <el-table-column
                    prop="userAccount"
                    label="账号"
                    align="center"
                />
                <el-table-column
                    prop="createTime"
                    label="创建时间"
                    align="center"
                />
            </el-table>
    </el-dialog>
    </div>
  </template>
  
  <script>
  import request from '@/utils/request'
  export default {
    components: { },
    data() {
      return {
        tableUserData2:[],
        tableUserData:[],
        loading:false,
        roleName:[],
        dialogVisible:false,
        title: '查看历史',
        userList :[],
        selectuser:null,
        total: 0,
        size: 10,
        page: 1
      }
    },
    mounted() {
      this.$nextTick(() => {
        this.getUserList()
      })
    },
    methods: {  
        synchQyronous(){
          request({
              url: '/ht-bpmn/departmentUser/pullData',
              method: 'get'
          }).then(res => {
              if (res.code == 200) {
                this.$message.success('同步成功')
                this.getUserList()
              } else {
                this.$message.error(res.msg)
              }
          })
        },
        getDepUser(v){
            this.tableUserData2 = []
            request({
                url: '/ht-bpmn/departmentUser/getUserByDepartId/'+v,
                method: 'get'
            }).then(res => {
                this.dialogVisible = true
                if(res.code==200){
                    this.tableUserData2 = res.data 
                }
            })
        },
        tableRowClassName({ row, rowIndex }) {
            if (rowIndex % 2 == 1) {
                return 'warningRow'
            } else {
                return ''
            }
        },
        getRowClass({ rowIndex, columnIndex }) {
            if (rowIndex == 0) {
                return 'background:#f2f5f8;fontSize:14px;color:#515a6e;'
            }
        },
        getUserList() {
            this.loading=true
            request({
                url: '/ht-bpmn/department/list',
                method: 'get'
            }).then(res => {
                this.tableUserData = res.data
                this.loading=false
            })
        }
        }
    }
  </script>
  
  <style lang="scss" scoped>
    // @import "~@/assets/styles/auto.scss";
    >>>.warningRow {
        background: #f2f5f8;
    }
    .fromClass{
      padding: 20px 0;
    }
        .info{
          margin-top: 20px;
        }
        .info>p{
          padding:4px 0;
          margin-left:80px;
          display: flex;
          flex-direction: row;
          justify-content: space-between;
        }
        .info>p:nth-child(1){
          color: #474747;
          font-weight: bold;
          background: #f1f4f7;
          padding-left: 0px;
        }
        .info>p>label{
          display: inline-block;
          width:35%;
        }
        .info>p>span{
          color:#494949;padding: 2px 4px;
          border-radius: 2px;font-size: 12px;
          background: #f0f0f0;
        }
      .ztree {
          margin-left:80px;
          border:1px solid #efefef;
          padding: 4px;
          border-radius: 2px;
          min-height: 270px;
          height: 300px;
          overflow-y: scroll;
      }
      .resoceDialog{
        display: flex;
        flex-direction: row;
        flex-wrap: nowrap;
        justify-content: space-between;
      }
      .resoceDialog>div>p{
        color: #464646;
        padding: 10px 0;
        font-weight: bold;
        // background: #f1f4f7;
        margin-left:26px;
        padding-left:0px;
        margin-bottom: 5px;
        text-align: right;
      }
        >>>.jsoneditor-poweredBy {
          display: none !important;
        }
  
        .addPs{
          display: flex;
          flex-direction: row;
          margin-bottom: 10px;
          >div{
            width:50%
          }
          span{
            display: inline-block;
            width: 10%;
          }
        }
        .autoClass{
          display: flex;
          flex-direction: row;
          flex-wrap: wrap;
        }
        .autoClass .el-form-item{
          width:50%;
        }
        .addcs{
          display: flex;
          flex-direction: row;
          margin-bottom: 10px;
        }
        .addcs2 .el-select {
          display: inline-block;
          width: 240px;
        }
        .autoInput{
          display: inline-block;
          width: 70%;
        }
        .infoTitle{
          border-bottom:1px solid #e5e5e5;
          margin-bottom: 30px;
          position: relative;
        }
        .infoTitle>span{
          position: absolute;
          left: 20px;
          background: #fff;
          width:80px;
          top:-15px;
          height:30px;
          text-align: center;
          line-height: 30px;
        }
          .el-select{
             width:100%;
          }
          .timing{
            background:#fff;
            padding:20px 10px;
          }
        </style>
  